import React, { Component } from 'react';
class App extends Component {
  // 01，定义  state 数据
  state = {
    num: 9
  }
  // 02，定义  更新state里num的方法
  updataNum = (val = 1) => {
    this.setState({ num: this.state.num + val })
  }
  render() {
    return (
      <div>
        <h1>状态state</h1>
        {/* 加 */}
        <button onClick={() => this.updataNum(2)}>{this.state.num}</button>
        {/* 减 */}
        <button onClick={() => this.updataNum(-2)}>{this.state.num}</button>
      </div>
    );
  }
}

export default App;